<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//登录控制器
//这里登录控制器只能继承Controller不能继承 CommonController
class LoginController extends Controller{
	
	public function index(){
		if(IS_POST){
			//用Q方法接收post过来的用户名和密码
			$username = Q('post.username');
			$password = Q('post.password','','md5');
			//用得到的用户名和密码和数据库里的user表匹配
			//select * from user where {$auname} and {$password};
			$adminuserData = Db::table('adminuser')->where("username='{$username}' AND password='{$password}'")->get();
			//sp($adminuserData);exit;
			//匹配成功返回真，不成功返回假
			if($adminuserData){
				$_SESSION['uid'] = $adminuserData[0]['uid'];
				$_SESSION['username'] = $adminuserData[0]['username'];
				$this->success('登录成功',U('Admin/Index/index'));
			}else{
				$this->error('用户名或密码错误');
			}
		}
	    View::make();
	}
	
	//退出登录方法
	public function out(){
	    unset($_SESSION['uid']);
		unset($_SESSION['username']);
		//完整路径是U('Admin/Login/index');
		go(U('index'));
	}
}








 ?>